<template>
  <div class="login-container">
    <!-- Logo区域 -->
    <div class="logo">
      <img alt="logo" src="/logo.svg" class="logo-img" />
      <div class="logo-text">福农跑腿管理后台</div>
    </div>

    <!-- 左侧背景图 -->
    <div class="banner">
      <div class="banner-content">
        <h1 class="banner-title">福农跑腿</h1>
        <p class="banner-subtitle">智能校园跑腿服务管理平台</p>
      </div>
    </div>

    <!-- 右侧登录表单 -->
    <div class="content">
      <div class="content-inner">
        <AdminLogin />
      </div>

      <!-- 页脚 -->
      <div class="footer">
        <div class="footer-text">© {{ currentYear }} 福农跑腿管理后台. All rights reserved.</div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { computed, onMounted } from 'vue';
import { useRouter } from 'vue-router';

import { useUserStore } from '@/stores';
import AdminLogin from '@/views/login/components/admin-login.vue';

const router = useRouter();
const userStore = useUserStore();
const currentYear = computed(() => new Date().getFullYear());

// 组件挂载时检查登录状态
onMounted(() => {
  // 如果已经登录，直接跳转到仪表板
  if (userStore.isLoggedIn) {
    router.replace({ name: 'Dashboard' });
  }
});
</script>

<style lang="less" scoped>
.login-container {
  display: flex;
  height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.logo {
  position: fixed;
  top: 24px;
  left: 22px;
  z-index: 1;
  display: inline-flex;
  align-items: center;

  &-img {
    width: 32px;
    height: 32px;
    margin-right: 8px;
  }

  &-text {
    color: white;
    font-size: 20px;
    font-weight: 600;
  }
}

.banner {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  max-width: 600px;
  background: linear-gradient(163.85deg, #1d2129 0%, #00308f 100%);

  &-content {
    text-align: center;
    color: white;
    padding: 0 60px;
  }

  &-title {
    font-size: 48px;
    font-weight: 700;
    margin-bottom: 16px;
    background: linear-gradient(45deg, #fff, #a8edea);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
  }

  &-subtitle {
    font-size: 18px;
    margin-bottom: 40px;
    color: rgba(255, 255, 255, 0.8);
  }

  &-features {
    text-align: left;
  }
}

.feature-item {
  display: flex;
  align-items: center;
  margin-bottom: 16px;
  font-size: 16px;

  &-icon {
    margin-right: 12px;
    color: #52c41a;
    font-size: 18px;
  }
}

.content {
  position: relative;
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  background-color: white;
  padding-bottom: 40px;

  &-inner {
    width: 100%;
    max-width: 400px;
    padding: 0 20px;
  }
}

.footer {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 100%;
  padding: 20px;
  text-align: center;

  &-text {
    color: var(--color-text-3);
    font-size: 12px;
  }
}

/* 响应式设计 */
@media (max-width: 1200px) {
  .banner {
    width: 25%;
  }
}

@media (max-width: 768px) {
  .login-container {
    flex-direction: column;
  }

  .banner {
    width: 100%;
    height: 200px;

    &-content {
      padding: 0 20px;
    }

    &-title {
      font-size: 32px;
    }

    &-subtitle {
      font-size: 14px;
      margin-bottom: 20px;
    }
  }

  .feature-item {
    margin-bottom: 8px;
    font-size: 14px;
  }

  .logo {
    position: relative;
    top: 16px;
    left: 16px;

    &-text {
      font-size: 16px;
    }
  }
}
</style>
